package solver

func (g *Grid) Set(rowNum int, colNum int, value uint8) {
	g.cells[rowNum][colNum].set(value)
	g.rows[rowNum].solvedCount += 1
	g.cols[colNum].solvedCount += 1
	boxNum, _ := calcBoxAndCellNum(rowNum, colNum)
	g.boxes[boxNum].solvedCount += 1
	g.solvedCount += 1
	g.ClearupInRow(rowNum, colNum)
	g.ClearupInCol(rowNum, colNum)
	g.ClearupInBox(rowNum, colNum)
}

func (g *Grid) prepareStrategies() {
	g.strategies = append(g.strategies, g.HiddenSingleInBoxes)
	g.strategyNames = append(g.strategyNames, "HiddenSingleInBoxes")

	g.strategies = append(g.strategies, g.HiddenSingleInRows)
	g.strategyNames = append(g.strategyNames, "HiddenSingleInRows")

	g.strategies = append(g.strategies, g.HiddenSingleInCols)
	g.strategyNames = append(g.strategyNames, "NakedSingle")

	g.strategies = append(g.strategies, g.NakedSingle)
	g.strategyNames = append(g.strategyNames, "HiddenSingleInCols")

	g.strategies = append(g.strategies, g.Pointing)
	g.strategyNames = append(g.strategyNames, "Pointing")

	g.strategies = append(g.strategies, g.Claiming)
	g.strategyNames = append(g.strategyNames, "Claiming")

	g.strategies = append(g.strategies, g.HiddenPair)
	g.strategyNames = append(g.strategyNames, "HiddenPair")

	g.strategies = append(g.strategies, g.NakedPair)
	g.strategyNames = append(g.strategyNames, "NakedPair")

	g.strategies = append(g.strategies, g.HiddenTriple)
	g.strategyNames = append(g.strategyNames, "HiddenTriple")

}

func (g *Grid) Solve() {
	used := false

	for {
		for _, strategy := range g.strategies {
			used = strategy()
			if used {
				//fmt.Println(g.strategyNames[i])
				break
			}
		}

		if !used {
			break
		}
		used = false
	}
}
